{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "killing-amsterdam",
   "metadata": {},
   "source": [
    "# Draws a map based on long/lat data and an associated float\n",
    "\n",
    "CSV data format requirement: longitude, latitude, value\n",
    "\n",
    "WARNING: This component currently only supports local execution (not Kubeflow/Airflow)  \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "legislative-database",
   "metadata": {},
   "outputs": [],
   "source": [
    "# @param data_dir temporal data storage for local execution\n",
    "# @param data_csv path and csv file name\n",
    "# @param master url of master (default: local mode)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "tribal-newcastle",
   "metadata": {},
   "outputs": [],
   "source": [
    "!pip3 install pyspark==3.1.1 folium==0.12.1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "informed-bonus",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import pandas as pd\n",
    "import folium\n",
    "from folium.plugins import HeatMap"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "encouraging-islam",
   "metadata": {},
   "outputs": [],
   "source": [
    "data_parquet = os.environ.get('data_parquet', 'data.parquet')\n",
    "master = os.environ.get('master', \"local[*]\")\n",
    "data_csv = os.environ.get('data_csv', 'data.csv')\n",
    "data_dir = os.environ.get('data_dir', '../../data/')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "accessible-welsh",
   "metadata": {},
   "outputs": [],
   "source": [
    "data_csv = 'trends.csv'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "systematic-aruba",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv(data_dir + data_csv)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "devoted-advertising",
   "metadata": {},
   "outputs": [],
   "source": [
    "data = df.reset_index(drop=True).values.tolist()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "correct-example",
   "metadata": {},
   "outputs": [],
   "source": [
    "m = folium.Map([48.0, 5.0], zoom_start=6)\n",
    "HeatMap(data).add_to(m)\n",
    "m"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
